package com.crm.controller.dy;

import com.crm.pojo.CrmDepository;
import com.crm.service.DepositoryService;
import com.crm.utils.R;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 仓库管理
 */
@RestController
@RequestMapping("/depository")
public class DepositoryController {
    @Autowired
    private DepositoryService depositoryService;

    //添加仓库
    @RequestMapping(value = "/addDepository", method = RequestMethod.POST)
    public R addDepository(CrmDepository crmDepository) {
        R r = new R();
        int n=depositoryService.addDepository(crmDepository);
        if(n>0){
            return r.ok();
        }else {
            return r.err();
        }
    }

    //删除仓库
    @RequestMapping(value = "/delDepository", method = RequestMethod.POST)
    public R delDepository(Integer dId) {
        R r = new R();
        int n=depositoryService.delDepository(dId);
        if(n>0){
            return r.ok();
        }else {
            return r.err();
        }
    }

    //编辑仓库
    @RequestMapping(value = "/updateDepository", method = RequestMethod.POST)
    public R updateDepository(CrmDepository crmDepository) {
        R r = new R();
        int n=depositoryService.updateDepository(crmDepository);
        if(n>0){
            return r.ok();
        }else {
            return r.err();
        }
    }

    //查询所有仓库
    @RequestMapping(value = "/selectDepository", method = RequestMethod.POST)
    public R selectDepository() {
        R r = new R();
        List<CrmDepository> c =depositoryService.selectDepository();
        if(c!=null){
            return r.okR(c);
        }else {
            return r.err();
        }
    }
}
